package cn.yq.aio.ui.main.chengfen;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

import cn.yq.aio.R;

/**
 * @AUTHOR YangLu
 * @Time 2021-03-25
 * @todo 人体成分
 */
public class ChengfenAdapter extends RecyclerView.Adapter<ChengfenAdapter.MyVH> {

    List<ChengFenBean> lists;

    public void setLists(List<ChengFenBean> lists) {
        this.lists = lists;
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public MyVH onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_cheng_fen, parent, false);
        return new MyVH(view);
    }

    @Override
    public void onBindViewHolder(@NonNull MyVH holder, int position) {
        holder.name_item_cheng_fen.setText(lists.get(position).getName());
        holder.danwei_item_cheng_fen.setText(lists.get(position).getDanwei());
        holder.status_item_cheng_fen.setText(lists.get(position).getStatus());
        holder.num_item_cheng_fen.setText(lists.get(position).getMin() + "~" + lists.get(position).getMax());
        holder.tips_item_cheng_fen.setText(lists.get(position).getDescribe());
    }

    @Override
    public int getItemCount() {
        return lists == null ? 0 : lists.size();
    }

    class MyVH extends RecyclerView.ViewHolder {

        TextView name_item_cheng_fen, danwei_item_cheng_fen, status_item_cheng_fen,
                num_item_cheng_fen, tips_item_cheng_fen;

        public MyVH(@NonNull View itemView) {
            super(itemView);
            name_item_cheng_fen = itemView.findViewById(R.id.name_item_cheng_fen);
            danwei_item_cheng_fen = itemView.findViewById(R.id.danwei_item_cheng_fen);
            status_item_cheng_fen = itemView.findViewById(R.id.status_item_cheng_fen);
            num_item_cheng_fen = itemView.findViewById(R.id.num_item_cheng_fen);
            tips_item_cheng_fen = itemView.findViewById(R.id.tips_item_cheng_fen);
        }
    }
}
